from PyQt5.QtWidgets import QApplication, QWidget
from ui_test2 import Ui_Form

class MyTest(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.ui = Ui_Form()
        self.ui.setupUi(self)
        self.default_data = {
            'comboBox_kecheng': '信息系统',
            'lineEdit_laoshi': '谢教员',
            'textEdit_jianjie':'信息系统课程简介。。。',
            'spinBox_keshishu': 60,
            'dateEdit_kaikeshijian': '2024-09-01'
        }

    def on_pushButton_pressed(self):
        data = {}
        data['comboBox_kecheng'] = self.ui.comboBox_kecheng.currentText()
        data['lineEdit_laoshi'] = self.ui.lineEdit_laoshi.text()
        data['textEdit_jianjie'] = self.ui.textEdit_jianjie.toPlainText()
        data['spinBox_keshishu'] = self.ui.spinBox_keshishu.value()
        data['dateEdit_kaikeshijian'] = self.ui.dateEdit_kaikeshijian.text()
        print(data)
        self.ui.label_msg.setText('读取表单数据')
        self.ui.textBrowser.setText(str(data))

    def on_pushButton_2_pressed(self):
        self.ui.label_msg.setText('载入默认数据')
        self.ui.textBrowser.clear()
        self.ui.comboBox_kecheng.setCurrentText(self.default_data['comboBox_kecheng'])
        self.ui.lineEdit_laoshi.setText(self.default_data['lineEdit_laoshi'])
        self.ui.textEdit_jianjie.setText(self.default_data['textEdit_jianjie'])
        self.ui.spinBox_keshishu.setValue(self.default_data['spinBox_keshishu'])
        from datetime import date
        self.ui.dateEdit_kaikeshijian.setDate(
            date.fromisoformat(self.default_data['dateEdit_kaikeshijian']))
        
app = QApplication([])
test = MyTest()
test.show()
app.exec_()